package com.example.ck.controller;

import com.example.ck.entity.Expertsign;
import com.example.ck.service.ExpertsignService;
import com.example.ck.vo.ResultVo;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Map;

/**
 * 专家签名表(Expertsign)表控制层
 *
 * @author makejava
 * @since 2024-03-26 21:59:40
 */
@Slf4j
@RestController
@RequestMapping("sign")
@CrossOrigin
public class ExpertsignController {
    @Autowired
    private ExpertsignService signService;

    @PostMapping("/add")
    private ResultVo addExpertsign(@RequestBody Expertsign expertsign) {
        boolean b = signService.addExpertsign(expertsign);
        ResultVo vo = new ResultVo<>();
        if (b) {
            vo.setSuccess(true);
            vo.setCode(200);
            vo.setData(expertsign);
        } else {
            vo.setSuccess(false);
            vo.setCode(201);
        }
        return vo;
    }

    @GetMapping("find")
    private ResultVo findExpertsign(String expertName) {
        ResultVo vo = new ResultVo<>();
        Expertsign expertsign = signService.findExpertsign(expertName);
        if (expertsign != null) {
            vo.setSuccess(true);
            vo.setCode(200);
            vo.setData(expertsign);
        } else {
            vo.setSuccess(false);
            vo.setCode(200);
            vo.setData(expertsign);
        }
        return vo;
    }

    /**
     * 根据姓名,修改电子签名
     */
    @PutMapping("/update")
    private ResultVo updateExpertsign(@RequestParam String expertName, @RequestBody String expertSign) {
        boolean b = signService.updateExpertsign(expertName, expertSign);
        if (b) {
            return new ResultVo(200, "修改成功", true);
        } else {
            return new ResultVo(201, "修改失败", false);
        }
    }
}

